<?php
/** [模型控制器]
 * @Author: 976123967@qq.com
 * @Date:   2015-01-09 16:59:21
 * @Last Modified by:   Administrator
 * @Last Modified time: 2015-01-09 18:09:55
 */
class ModelAction extends PublicAction{


	public $logic;

	/**
	 * [_initialize 初始化]
	 * @return [type] [description]
	 */
	public function _initialize()
	{
		parent::_initialize();
		$this->logic = D('Model','Logic');
		
	}

	/**
	 * [index 模型列表]
	 * @return [type] [description]
	 */
	public function index()
	{
	
		// 读取所有模型
		$data = $this->logic->get_all();
		$this->assign('data',$data);
		$this->display();
	}

	/**
	 * [edit 编辑]
	 * @return [type] [description]
	 */
	public function edit()
	{

		if(IS_POST)
		{
			// 更新
			if(!$this->logic->update_model())
				$this->error($this->logic->getError());
			$this->success('模型修改成功',U('Model/index'));
			die;
		}

		
		// 读取一条数据
		$field = $this->logic->find_one();
		if(!$field)
			$this->error($this->logic->getError());
		$this->assign('field',$field);
		$this->display();
	}

	/**
	 * [add 添加]
	 */
	public function add()
	{
		if(IS_POST)
		{
			// 更新
			if(!$this->logic->add_model())
				$this->error($this->logic->getError());
			$this->success('模型添加成功',U('Model/index'));
			die;
		}
		$this->display();
	}



	/**
	 * [update_cache 更新缓存]
	 * @return [type] [description]
	 */
	public function update_cache()
	{
		$this->logic->update_cache();
		$this->success('模型缓存更新成功',U('Model/index'));
	}
	/**
	 * [del 删除模型]
	 * @return [type] [description]
	 */
	public function del()
	{
		if(!$this->logic->delete_model())
			$this->error($this->logic->getError());
		$this->success('模型删除成功',U('Model/index'));

	}
}